package com.lanyan.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;
        import com.lanyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.lanyan.common.utils.StringUtils;
import com.lanyan.system.mapper.BalanceHistoryMapper;
import com.lanyan.system.domain.BalanceHistory;
import com.lanyan.system.domain.vo.BalanceHistoryVo;
import com.lanyan.system.service.IBalanceHistoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 余额流水Service业务层处理
 *
 * @author lanyan
 * @date 2024-11-26
 */
@Service
public class BalanceHistoryServiceImpl  extends ServiceImpl<BalanceHistoryMapper,BalanceHistory> implements IBalanceHistoryService

{
    @Autowired
    private BalanceHistoryMapper balanceHistoryMapper;

    /**
     * 查询余额流水
     *
     * @param balanceHistoryId 余额流水主键
     * @return 余额流水
     */
    @Override
    public BalanceHistory selectBalanceHistoryByBalanceHistoryId(Long balanceHistoryId)
    {
        return this.getById(balanceHistoryId);
    }

    /**
     * 查询余额流水Vo列表
     *
     * @param balanceHistory 余额流水
     * @return 余额流水
     */
    @Override
    public List<BalanceHistoryVo> selectBalanceHistoryVoList(BalanceHistory balanceHistory)
    {
        return selectBalanceHistoryList(balanceHistory)
                .stream()
                .map(x -> (BalanceHistoryVo)x)
                .collect(Collectors.toList());
    }
    /**
     * 查询余额流水列表
     *
     * @param balanceHistory 余额流水
     * @return 余额流水
     */
    @Override
    public List<BalanceHistory> selectBalanceHistoryList(BalanceHistory balanceHistory)
    {
        LambdaQueryChainWrapper<BalanceHistory> wrapper = this.lambdaQuery().eq(BalanceHistory::getDelFlag,"0");
        if (balanceHistory.getAccountId() != null) {
            wrapper.eq(BalanceHistory::getAccountId, balanceHistory.getAccountId());
        }
        if (balanceHistory.getMoney() != null) {
            wrapper.eq(BalanceHistory::getMoney, balanceHistory.getMoney());
        }
        if (StringUtils.isNotEmpty(balanceHistory.getType())) {
            wrapper.eq(BalanceHistory::getType, balanceHistory.getType());
        }
        if (StringUtils.isNotEmpty(balanceHistory.getTitle())) {
            wrapper.eq(BalanceHistory::getTitle, balanceHistory.getTitle());
        }
        if (StringUtils.isNotEmpty(balanceHistory.getMessage())) {
            wrapper.eq(BalanceHistory::getMessage, balanceHistory.getMessage());
        }
        if (StringUtils.isNotEmpty(balanceHistory.getPointTo())) {
            wrapper.eq(BalanceHistory::getPointTo, balanceHistory.getPointTo());
        }
        return wrapper.list();
    }

        /**
         * 新增余额流水
         *
         * @param balanceHistory 余额流水
         * @return 结果
         */
    @Override
        public boolean insertBalanceHistory(BalanceHistory balanceHistory)
        {
                    balanceHistory.setCreateTime(DateUtils.getNowDate());
                return this.save(balanceHistory);
        }

        /**
         * 修改余额流水
         *
         * @param balanceHistory 余额流水
         * @return 结果
         */
    @Override
        public boolean updateBalanceHistory(BalanceHistory balanceHistory)
        {
                    balanceHistory.setUpdateTime(DateUtils.getNowDate());
            return this.updateById(balanceHistory);
        }

        /**
         * 批量删除余额流水
         *
         * @param balanceHistoryIds 需要删除的余额流水主键
         * @return 结果
         */
    @Override
        public boolean deleteBalanceHistoryByBalanceHistoryIds(Long[] balanceHistoryIds)
        {
            return this.lambdaUpdate().set(BalanceHistory::getDelFlag,"1").in(BalanceHistory::getBalanceHistoryId,balanceHistoryIds).update();
        }

        /**
         * 删除余额流水信息
         *
         * @param balanceHistoryId 余额流水主键
         * @return 结果
         */
    @Override
        public boolean deleteBalanceHistoryByBalanceHistoryId(Long balanceHistoryId)
        {
            return this.lambdaUpdate().set(BalanceHistory::getDelFlag,"1").eq(BalanceHistory::getBalanceHistoryId,balanceHistoryId).update();
        }
    }
